import java.util.ArrayList;
import java.util.List;

public class Subsets {

    List<List<Integer>> ans = new ArrayList<>();

    public List<List<Integer>> subsets(int[] nums) {
        ArrayList<Integer> temp = new ArrayList<>();
        process(nums, 0, temp, ans);
        return ans;
    }

    public void process(int[] nums, int i, List<Integer> temp, List<List<Integer>> list) {
        if (i == nums.length) {
            list.add(copy(temp));
            return;
        }
        process(nums, i + 1, temp, list);
        temp.add(nums[i]);
        process(nums, i + 1, temp, list);
        temp.remove(temp.size() - 1);
    }

    public List<Integer> copy(List<Integer> list) {
        ArrayList<Integer> integers = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            integers.add(list.get(i));
        }
        return integers;
    }
}
